package com.kugou.miniapp.test;

import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    private static class Node{
        Node(){}
        Node(String id){
            this.id = id;
        }
        String id;
        Node left;
        Node right;
        Node par;
    }

    static int res = 0;
    public static void main(String[] args) {
        Main a = new Main();
        Main b = new Main();
        new Thread(new Runnable() {
            @Override
            public void run() {
//                int c = 10/0;
                try {
                    b.fun();
//                    a.fun();
//                    new Main().fun();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
//                    a.fun();
                    a.fun();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

    }//main end

    public void fun() throws InterruptedException {
        synchronized (Main.class){
            System.out.println("abc enter"+" "+Thread.currentThread().getName());
            Thread.sleep(3000);
            System.out.println("abc out"+" "+Thread.currentThread().getName());
        }
    }

    public static boolean isLeaf(Node node){
        if (node.left == null && node.right == null){
//            System.out.println("y:"+node.id);
            return true;
        }else {
            int i = 0;
            if (node.left != null){
                if (isLeaf(node.left)){
                    i++;
                }
            }
            if (node.right != null){
                if (isLeaf(node.right)){
                    i++;
                }
            }
            if (i == 2){
                res++;
            }
        }
        return false;
    }

    public static void addNode(Node par_node, String addNode_str, String dest, Map map){
        Node addNode = (Node) map.get(addNode_str);
        if (addNode == null){
            addNode = new Node(addNode_str);
            map.put(addNode_str, addNode);
        }
        if (dest.equals("left")){
            par_node.left = addNode;
        }else {
            par_node.right = addNode;
        }
        addNode.par = par_node;
    }
}